<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('股票黑名单') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('股票名称')" prop="stockName">
        <el-input
          v-model="queryParams.stockName"
          :placeholder="$t('股票名称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('股票代码')" prop="stockCode">
        <el-input
          v-model="queryParams.stockCode"
          :placeholder="$t('股票代码')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('进入时间')" prop="entryTime">
        <DatePicker
          v-model="dateRange"
          type="daterange"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['risk:restricted:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t('新增') }}
        </el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" tooltip-effect="darkTable" :data="riskSharesRestrictedList" border>
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('股票名称')" align="center" prop="stockName" show-overflow-tooltip>
        <template slot-scope="scope">
          <el-link type="primary" @click="updateHandle(scope.row)">{{ scope.row.stockName }}</el-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('股票代码')" align="center" prop="stockCode" show-overflow-tooltip />
      <el-table-column :label="$t('进入时间')" align="center" prop="entryTime" width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.entryTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('创建人')" align="center" prop="createName" />
      <el-table-column :label="$t('进入理由')" align="center" prop="reasonsForEntry" show-overflow-tooltip />
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['risk:restricted:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row)"
          >{{ $t('修改') }}
          </el-button>
          <el-button
            v-hasPermi="['risk:restricted:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}
          </el-button>
          <el-button
            v-hasPermi="['risk:restricted:edit']"
            size="small"
            type="text"
            icon="el-icon-open"
            @click="relieveBlack(scope.row)"
          >{{ $t('解除限制') }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 修改和查看 -->
    <el-dialog
      :title="$t(title)"
      :visible.sync="formOpen"
      :close-on-click-modal="false"
      :lock-scroll="false"
      custom-class="dialogForm"
      append-to-body
    >
      <riskSharesRestrictedForm ref="riskSharesRestrictedForm" />
    </el-dialog>
    <!-- 解除限制 -->
    <el-dialog
      :title="$t('解除股票限制名单')"
      :visible.sync="formOpen2"
      :close-on-click-modal="false"
      :lock-scroll="false"
      custom-class="dialogForm"
      append-to-body
    >
      <relieve ref="relieve" />
    </el-dialog>
  </div>
</template>

<script>
import {
  listRiskSharesRestricted,
  delRiskSharesRestricted
} from '@/api/deal/risk/shares/restricted/riskSharesRestricted'
import riskSharesRestrictedForm from './riskSharesRestrictedForm.vue'
import relieve from './relieveBlack.vue'

export default {
  components: {
    riskSharesRestrictedForm,
    relieve
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 股票限制名单表格数据
      riskSharesRestrictedList: [],
      // 弹出层标题
      title: '股票黑名单',
      // 是否显示弹出层
      formOpen: false,
      formOpen2: false,
      // 查询参数
      queryParams: {
        stockName: undefined,
        stockCode: undefined,
        reasonsForEntry: undefined,
        exitTime: undefined,
        reasonsForExit: undefined,
        status: '1',
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {},
      dateRange: [],
      // 表单校验
      rules: {}
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询股票限制名单列表 */
    getList() {
      this.loading = true
      listRiskSharesRestricted(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.riskSharesRestrictedList = response.rows
        this.total = response.total
        this.loading = false
      })
    },

    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        delFlag: undefined,
        stockName: undefined,
        stockCode: undefined,
        reasonsForEntry: undefined,
        exitTime: undefined,
        reasonsForExit: undefined,
        status: '0'
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.dateRange = undefined
      this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
      this.formOpen = true
      this.$nextTick(() => {
        this.$refs.riskSharesRestrictedForm.init(null)
      })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
      this.formOpen = true
      this.$nextTick(() => {
        // 调用form页面的 init 方法初始化数据
        this.$refs.riskSharesRestrictedForm.init(row)
      })
    },
    relieveBlack(row) {
      this.formOpen2 = true
      this.$nextTick(() => {
        // 调用form页面的 init 方法初始化数据
        this.$refs.relieve.init(row)
      })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
      this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(function() {
        return delRiskSharesRestricted(row.id)
      }).then(() => {
        this.getList()
        this.msgSuccess(this.$t('删除成功'))
      }).catch(function() {
      })
    }

  }
}
</script>
